<?php

namespace DatMoment\VideoBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class DefaultControllerTest extends WebTestCase
{
    public function testIndex()
    {
        $client = static::createClient();

        $crawler = $client->request('GET', '/hello/Fabien');

        $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
    }
    
    public function informationsURLAction() {
       $infosVideo = getVideoInfo("http://www.dailymotion.com/video/x28hn6t_quand-manuel-valls-rencontre-zahia-a-la-fiac-zapping-actu-du-23-10-2014_news");
       $content = $this->get('templating')->render('DatMomentVideoBundle:Default:test.html.twig', array('infosVideo' => $infosVideo));
       return new Response($content);
    }
    
    public function ORMCategorieAction() {
        $doctrine = $this->getDoctrine();
        $entityManager = $doctrine->getManager();
        
        $categorieOperations = new Operations\CategorieOperations($entityManager);
//        $cat = new Categorie();
//        $cat->setName('test2');
//        $categorieOperations->initialisationCategorie($cat);
//        $categorieOperations->persist();
//        $test = $categorieOperations->findOneByName('test2');
        $categorieOperations->createCategorie("test");
        $categorieOperations->persist();
//        $test = $categorieOperations->findOneByName("Fun");
        
        $content = $this->get('templating')->render('DatMomentVideoBundle:Default:index.html.twig', array('test' => $test));
        return new Response($content);
        
    }
    
    public function ORMJeuxAction() {
        $doctrine = $this->getDoctrine();
        $entityManager = $doctrine->getManager();
        $jeuxOperation = new Operations\JeuxOperations($entityManager);
        $jeuxOperation->persist();
        
        $content = $this->get('templating')->render('DatMomentVideoBundle:Default:index.html.twig');
        return new Response($content);
    }
    
    public function ORMAppreciationAction() {
        $doctrine = $this->getDoctrine();
        $entityManager = $doctrine->getManager();
        
        $appreciationOperations = new Operations\AppreciationOperations($entityManager);
        $videoOperations = new Operations\VideoOperations($entityManager);
        $user = $this->container->get('security.context')->getToken()->getUser();
        $videoOperations->createVideo('testIdVideo', 'testTitre', 'testType', 'testDescription', 'testImg', 'testCode', array('Fun','Pure Skill','test'), $user);
        $video = $videoOperations->getVideo();
        
        
        $appreciationOperations->createAppreciation('test', 5, $user, $video);
        $result = $appreciationOperations->findAllAppreciationByVideo($video);
        
        $content = $this->get('templating')->render('DatMomentVideoBundle:Default:index.html.twig', array('result' => $result));
        return new Response($content);
    }
    
    public function ORMVideoAction() {
        $doctrine = $this->getDoctrine();
        $entityManager = $doctrine->getManager();
        
        $videoOperations = new Operations\VideoOperations($entityManager);
        $user = $this->container->get('security.context')->getToken()->getUser();
        $videoOperations->createVideo('testIdVideo', 'testTitre', 'testType', 'testDescription', 'testImg', 'testCode', array('Fun','Pure Skill','test'), $user);
        $videoOperations->persist();
        $video = $videoOperations->getVideo();
        $stringCategories = $videoOperations->getCategoriesString($video);
        
        $content = $this->get('templating')->render('DatMomentVideoBundle:Default:objectVideo.html.twig', array('video' => $video, 'stringCategories' => $stringCategories));
        return new Response($content);
    }
}
